<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>下午茶生产查询列表</title>
    <!--{include file='comm/icheck.tpl'}-->
    <!--{include file='comm/comm_editor.tpl'}-->
</head>
<body>

<div class="container">
   
    <div class="comm_content">

            <div  class="search-box">
                <form id="searchForm" class="form-inline" onsubmit="return false;">
                    <div style="position:relative">
                        <span>
                            <span style='width:60px;text-align:right'>配送日期：</span>
                            <input type="text" class="form-control input-sm" style="width: 140px;" value="<!--{$currentDate}-->" name="apply_date" id="apply_date">
                        </span>
                        <span>
                            <span style='width:60px;text-align:right'>配送城市：</span>
                            <select id="cityID" name="cityID" class="form-control input-sm" style="width:100px;">
                                <option value="">请选择</option>
                            </select>
                        </span>
                        <span>
                            <span style='width:60px;text-align:right'>配送站：</span>
                            <select name="distribution_id" id="distribution_id" class="form-control input-sm" style="width:110px;">
                                <option value="">请选择</option>
                            </select>
                        </span>
                        <span>
                            <span style='width:50px;text-align:right'>状态：</span>
                            <select name="status" id="status" class="form-control input-sm" style="width:110px;">
                                <option value="all">全部</option>
                                <option value="0">已提交</option>
                                <option value="1">已生产</option>
                                <option value="2">已上车</option>
                                <option value="3">入库</option>
                                <option value="10">已取消</option>
                            </select>
                        </span>
                         <span>
                            <span style='width:60px;text-align:right'>申请编号：</span>
                            <input type="text" class="form-control input-sm" style="width:140px" value="" name="apply_id" id="apply_id">
                        </span>
                        <span>
                            <input type="button" class="btn btn-primary" value="查询" onclick="coupon.search();">&nbsp;&nbsp;
                            <input type="button" class="btn btn-warning btn-sm" value="重置" onclick="coupon.cz();">&nbsp;&nbsp;
                        </span>
                    </div>
                </form>
            </div>

            <table id="flex" style="display:none"></table>

        </div>

</div>

<script type="text/javascript">


    $('#apply_date').datepicker();

    $("#flex").flexigrid({
        url:"/invokingAjax-backend/production/applySearch.ajax?operFlg=1&apply_date="+$("#apply_date").val(),
        dataType: "json",
        colModel : [
            {display: "操作", width : 150, align: 'center'},
            {display: "申请编号", width : 120, align: 'center'},
            {display: "状态", width : 120, align: 'center'},
            {display: "配送日期", width : 120, align: 'center'},
            {display: "配送站", width : 120, align : 'center' },
            {display: "申请时间", width : 150, align: 'center'},
            {display: "申请人", width : 120, align: 'center'},
            {display: "申请数量", width : 120, align: 'center'},
            {display: "入库数量", width : 120, align: 'center'},
            {display: "申请商品详情", width : 450, align: 'left'},
            {display: "入库商品详情", width : 450, align: 'left'},
            {display: "备注", width : 300, align: 'left'}

        ],
        buttons : [
            {name: "添加采购单", bclass: "add", onpress : "coupon.add"},
            {separator: true},
          /*  {name: "删除", bclass: "delete", onpress : "coupon.reset"},
            {separator: true},*/


        ],
        sortname: "apply_id",
        sortorder: "desc",
        usepager: true,
        rp: 10,
        useRp: true
    });

    var coupon = {

        //查询
        search : function (){
            var dt = $("#searchForm").serializeArray();
            $("#flex").flexOptions({newp: 1, params: dt}).flexReload();
        },
        cz : function(){
            $("#cityID").val('');
            $('#distribution_id').val('');
            $('#status').val('all');
            $('#apply_id').val('');
            $("#apply_date").val('<!--{$currentDate}-->');

            var dt = $("#searchForm").serializeArray();
            $("#flex").flexOptions({newp: 1, params: dt}).flexReload();
        },
        add : function(){
            E.open("/quanliadmin/app/production/applySearch.pscript?operFlg=2", "" , {height: 650,width:800, top: 100, left: 300});
        },

        //删除
        reset : function(){
            var selected_count = $('.trSelected',flex).length;
            if (selected_count==0) {
                E.alert("请选择要删除的数据");
                return;
            }
            E.confirm("确定删除此申请单么？","coupon.trueRest");


        },
        trueRest : function(){
            var selected_count = $('.trSelected',flex).length;
            if (selected_count==0) {
                E.alert("请选择要删除的数据");
                return;
            }
            var selected_count = $('.trSelected',flex).length;
            if (selected_count==0) {
                E.alert("请选择要删除的数据");
                return;
            }

            var tempArr = new Array();
            for(var i=0; i<selected_count; i++){
                var templateIDStr = $('.trSelected',flex).eq(i).attr('id');
                var templateIDStr = templateIDStr.substr(3);
                tempArr.push(templateIDStr);
            }

            E.ajax_post({
                url: "/invokingAjax-backend/production/applySearch.ajax?operFlg=3",
                data: {
                    applyID : tempArr
                },
                call: function(o){
                    if(o.code==200){
                        E.alert('采购单已删除',2);
                        coupon.search();
                    }else{
                        E.alert(o.message);
                    }

                }
            });

        },
        //生产
        shengchan:function(applyID){
            coupon.applyFun(applyID,1,"生产");
        },
        //取消
        quxiao:function(applyID){
            coupon.applyFun(applyID,10,"取消");
        },
        //上车
        shangche:function(applyID){
            coupon.applyFun(applyID,2,"上车");
        },
        //入库
        ruku:function(applyID){
            E.open("/quanliadmin/app/production/applySearch.pscript?operFlg=3&applyID="+applyID, "" , {height: 350,width:800, top: 100, left: 300});
        },
        applyFun:function(applyID,status,messge){
            E.confirm("确定"+messge+"么？",function(){
                E.ajax_post({
                    url: "/invokingAjax-backend/production/applySearch.ajax?operFlg=4",
                    data: {
                        applyID : applyID,
                        status:status
                    },
                    call: function(o){
                        if(o.code==200){
                            E.alert("采购单已"+messge,2);
                            coupon.search();
                        }else{
                            E.alert(o.message);
                        }

                    }
                });
            });
        }
    };



    $(window).ready(function() {

        $("#cityID").html("");

        var cityHtml = '<option value="">请选择</option>';

        $.ajax({
            type: "post",
            url: "/invokingAjax-comm/bill/distribution.ajax?operFlg=1",
            dataType: "json",
            data: "",
            success: function( result_obj ) {
                if(result_obj.code == 200){
                    $.each(result_obj.data, function(i,val){
                        cityHtml +='<option value="'+val.id+'">'+val.name+'</option>';
                    });
                    $('#cityID').html(cityHtml);
                }else{
                    E.alert(result_obj.message);
                }
            }
        });

        //点击城市联动获得配送站(联动)
        $(document).on('change', '#cityID', function() {

            $('#distribution_id').html("");

            var cityID = $('#cityID').children('option:selected').val();
            var distributionHtml = '<option value="">请选择</option>';
            E.ajax_post({
                url: "/invokingAjax-comm/bill/distribution.ajax?operFlg=2",
                data: {deliver_cityid: cityID},
                call: function( obj ) {
                    if(obj.code ==200 && obj.data != null){

                        $.each(obj.data, function(i,val){
                            distributionHtml +='<option value="'+val.distribution_id+'">'+val.distribution_name+'</option>';
                        });
                        $('#distribution_id').html(distributionHtml);
                    }else{

                        distributionHtml += '';
                        $('#distribution_id').html(distributionHtml);
                    }
                }
            });
        });
    });

</script>

</body>
</html>